class bezier_patch : public base_object
{
public:
int mode; // 2 for quadratic and 3 for cubic
vector *p; // the surface control points
vector *t; // the surface texture control points
int np, // num points
npu, // num points in u dir
npv, // num points in v dir
nsu, // num segments in u dir
nsv;
// num segments in u dir
int levelu,levelv; // subdivision level in u and v
int nvertu,nvertv; // surface num vertices in u and v
int texpic,lm; // texture and lightmap
vector *surf; // discretized surface
vector pivot; // the pivot position
void reset();
int load_pch(char *file);
void build_loft(bezier_curve *shape,bezier_curve *path,int texture,int
lightmap,float tileu,float tilev);
void evaluate(int evaltype,float u,float v,vector *dest);
void build_surface();
void illuminate(vector& p,float rad,vector& color,int shadows);
void draw(int nleveldrop=0);
mesh *build_mesh();
bezier_patch() { p=0; t=0; surf=0; reset(); };
~bezier_patch() { reset(); };
};
Member | Type | Description |
---|---|---|
mode | int | Bezier patch mode: 3 for quadratic 4 for cubic |
pivot | vector | pivot position |
p | vector * | the patch control points array |
t | vector * | the patch coltrol points tetxure coordinates array (x,y) for texture map co-ordinates (z,w) for lightmap texture co-ordinates |
np | int | number of points in control points array |
npu | int | number of points in u dir |
npv | int | number of points in v dir |
nsu | int | number of segments in u dir |
nsv | int | number of segments in v dir |
levelu | int | subdivision level in u |
levelv | int | subdivision level in v |
nvertu | int | number of discretized vertices in u dir nvertu = (1<<levelu)+1 |
nvertv | int | number of discretized vertices in v dir nvertv = (1<<levelv)+1 |
texpic | int | texture applyed to the patch (-1 for none) |
lm | int | light_map applyed to the patch (-1 for none) |
surf | vector * | discretized surface points 2 vectors per entry (point and tetxure co-ordinates) size = 2*sizeof(vector)*nvertu*nvertv |
reset, build_loft, evaluate, build_surface, build_mesh, illuminate, draw, load_pch
This class implements a Bezier patch. The patch can have any number of segments in u and v directions. The patch is made of several connected cubic or quadratic Bezier patches (nsu is the numbre of patches in the u dir and nsv in the v dir).
For quadratic patches:
nsu = (spu-2)/2
nsv = (spv-2)/2
For cubic patches:
nsu = (spu-1)/2
nsv = (spv-1)/2
The surface is discretized based on the subdivision level. The number of vertices in u and v dir are:
nvertu = (1<<levelu)*nsu+1
nvertv = (1<<levelv)*nsv+1
At run-time, the surface car be draw at any level of detail up to its current selected level. The draw function includes a parameter that represents the number of levels of detail to drop on draw. The numbrer of vertices skipped (col/row draw loop increment) on each direction is:
nvertskip = (1<<nleveldrop)